package ru.aslanov.schedule.server;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * Created: Jan 29, 2010 12:05:01 PM
 *
 * @author Sergey Aslanov
 */
public class SmartGWTDataServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(SmartGWTDataServlet.class.getName());

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final Enumeration parameterNames = request.getParameterNames();
        StringBuffer sb = new StringBuffer();
        while (parameterNames.hasMoreElements()) {
            String paramName = (String) parameterNames.nextElement();
            final String paramValue = request.getParameter(paramName);
            sb.append(paramName + (paramValue != null ? (" = {" + paramValue + "}") : " is null") + " \n");
        }
        log.fine("Params:\n" + sb);

        try {
            ServiceFactory.dispatch(request, response);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }

}
